package com.itheima.health.util;

import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import sun.security.util.Password;

public class PasswordCheckUtil {


    public static boolean passwordCheck(String loginPassword,String dbPassword){

        //md5校验
        if (dbPassword.startsWith("{md5}")) {
            String password = new MD5().encode(loginPassword);
            if (dbPassword.equals("{md5}" + password)) {
                return true;
            }
        }
        //BCrypt校验
        if (dbPassword.startsWith("{bcrypt}")) {
//            String hashpw = BCrypt.hashpw(loginPassword, BCrypt.gensalt());
            if (BCrypt.checkpw(loginPassword,dbPassword.replace("{bcrypt}",""))){
                return true;

            }

        }
        //普通密码
        else{
            if (dbPassword.equals(loginPassword)){
                return true;
            }
        }
        return false;
    }
}
